﻿Public Class frmChonMatHangXuat

    Private Sub frmChonMatHangXuat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgvDSMatHang.DataSource = CMatHang.LoadMatHang()
    End Sub

    Private Sub btnDong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDong.Click
        Close()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim index = dgvDSMatHang.CurrentRow.Index
        Dim row = dgvDSMatHang.Rows.Item(index)
        If txtSoLuong.Text = "" Then
            MsgBox("Số lượng phải khác rỗng!", MsgBoxStyle.Information, "Thông báo")
            txtSoLuong.Focus()
            Return
        ElseIf Integer.Parse(txtSoLuong.Text) < 0 Then
            MsgBox("Số lượng phải lớn hơn 0", MsgBoxStyle.Information, "Thông báo")
            txtSoLuong.Focus()
            Return
        ElseIf Integer.Parse(txtSoLuong.Text) > Integer.Parse(row.Cells(6).Value.ToString()) Then
            txtSoLuong.Text = row.Cells(6).Value
        End If
        Dim count = frmThemPhieuXuat.dgvCTPhieuXuat.Rows.Count
        frmThemPhieuXuat.dgvCTPhieuXuat.Rows.Add(row.Cells(0).Value.ToString(), row.Cells(1).Value.ToString(), _
                                                 row.Cells(2).Value.ToString(), row.Cells(3).Value.ToString(), _
                                                 row.Cells(4).Value.ToString(), row.Cells(5).Value.ToString(), _
                                                 txtSoLuong.Text)

    End Sub
End Class